package com.ethan.ms.plugin.robot;

import org.mozilla.javascript.Context;
import org.mozilla.javascript.Script;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;

public class ScriptManager {

    private final Context context;
    private final Scriptable scope;
    private final Script script;

    public ScriptManager(Context context, Scriptable scope, Script script) {
        this.context = context;
        this.scope = scope;
        this.script = script;
        this.script.exec(this.context, this.scope);
    }

    public Object invokeFunction(String name, Object... args) throws Exception {
        return ScriptableObject.callMethod(context, scope, name, args);
    }
}
